<template>
	<el-row>
		<el-col>
			<common-top :mainTitle="global.triageName" separator="——" subtitle="病历详情"></common-top>
		</el-col>
		<el-col :span="18" :offset="3">
			<div id="doctorCase">
				<el-row>
					<el-col style="font-size:16pt;text-align:center;"><label>病历详情</label></el-col>
					<el-col :span="6" style="border-bottom:1px solid #000000;">
						<label>就诊卡号：</label><span>{{curPatient.recordCard}}</span>
					</el-col>
					<el-col :span="18" style="border-bottom:1px solid #000000;text-align:right;">
						<label>过敏史：</label>
						<span v-if="!curPatient.recordAllergy">无药物过敏史</span>
						<span v-if="curPatient.recordAllergy">{{curPatient.recordAllergy}}&nbsp;过敏</span>
					</el-col>
					<el-col :span="4">
						<label>姓名：</label><span>{{curPatient.recordName}}</span>
					</el-col>
					<el-col :span="4">
						<label>性别：</label><span>{{curPatient.recordSex}}</span>
					</el-col>
					<el-col :span="4">
						<label>年龄：</label><span>{{curPatient.recordAge}}</span>
					</el-col>
					<el-col :span="4">
						<label>电话：</label><span>{{curPatient.recordTel}}</span>
					</el-col>
					<el-col :span="8">
						<label>地址：</label><span>{{curPatient.recordAddress}}</span>
					</el-col>
					<el-col :span="4">
						<label>治疗科室：</label><span>{{curPatient.handlePlace}}</span>
					</el-col>
					<el-col :span="4">
						<label>去向：</label><span>{{curPatient.sendDept}}</span>
					</el-col>
					<el-col :span="14">
						<label>逗留时长：</label><span>{{curPatient.stayTime}}</span>
					</el-col>
					<el-col>
						<label>主诉：</label>
						<span>{{doctorCaseObj.complaint}}</span>
					</el-col>
					<el-col :span="4">
						<label>神志：</label><span>{{curPatient.recordSense}}</span>
					</el-col>
					<el-col :span="4">
						<label>体温：</label><span>{{curPatient.recordTemperature}}℃</span>
					</el-col>
					<el-col :span="4">
						<label>脉搏：</label><span>{{curPatient.recordPulseRate}}次/分</span>
					</el-col>
					<el-col :span="4">
						<label>呼吸：</label><span>{{curPatient.recordBreathRate}}次/分</span>
					</el-col>
					<el-col :span="4">
						<label>血压：</label><span>{{curPatient.recordSBP}}/{{curPatient.recordDBP}}mmHg</span>
					</el-col>
					<el-col>
						<label>一般情况：</label><span>{{curPatient.general}}</span>
					</el-col>
					<el-col>
						<label>病史体征：</label>
						<p class="caseDisposal" v-html="doctorCaseObj.symptom.replace(new RegExp('\r\n','gm'),'<br>').replace(new RegExp('\n','gm'),'<br>')"></p>
					</el-col>
					<el-col>
						<label>初步诊断：</label>
						<p class="caseDisposal"
						v-html="doctorCaseObj.diagnosis.replace(new RegExp('\r\n','gm'),'<br>').replace(new RegExp('\n','gm'),'<br>')"></p>
					</el-col>

					<el-col>
						<label>处置：</label>
						<p class="caseDisposal" v-html="doctorCaseObj.disposal.replace(new RegExp('\r\n','gm'),'<br>').replace(new RegExp('\n','gm'),'<br>')"></p>
					</el-col>
					<el-col class="recipeContent" v-for="(item,index) in recipeObj" :key="index">
						<el-row v-if="item.drugs.length==1" v-for="(drug,inde) in item.drugs" :key="inde">
							<el-col>
								{{drug.name}}&emsp;({{drug.spec}})×{{drug.number}}&emsp;
								<span v-show="drug.needTest=='1'">
									（皮试：{{item.skinTest?item.skinTest:"_____"}}）
								</span>
							</el-col>
							<el-col><label>sig:</label>&emsp;{{drug.single}}&emsp;{{item.usage}}&emsp;{{item.frequency}}×{{item.course}}</el-col>
						</el-row>
						<el-row v-if="item.drugs.length>1">
							<el-col>
								<el-row>
									<el-col v-for="(drug,inde) in item.drugs" :key="inde">
										{{drug.name}}&emsp;({{drug.spec}})×{{drug.number}}&emsp;
										<span v-show="drug.needTest=='1'">
											（皮试：{{item.skinTest?item.skinTest:"_____"}}）
										</span>
									</el-col>
								</el-row>
							</el-col>
							<el-col>
								<el-row> 
									<el-col :span="2"><label>sig:</label></el-col>
									<el-col :span="10">
										<el-row>
											<el-col v-for="(drug,inde) in item.drugs" :key="inde">
												{{drug.name}}&nbsp;{{drug.single}}
											</el-col>
										</el-row>
									</el-col>
									<el-col :span="1" class="line">
										<br v-for="(drug,inde) in item.drugs" :key="inde">
									</el-col>
									<el-col :span="7" :offset="1" :style="'line-height:'+item.drugs.length*30+'px'">
										&nbsp;{{item.usage}}&nbsp;{{item.frequency}}×{{item.course}}
									</el-col>
								</el-row>
							</el-col>
						</el-row>
					</el-col>

					<el-col :span="5" :offset="19">
						<label>医生签名：</label>
					</el-col>
					<el-col :span="5" :offset="19">
						<label>日期：</label><span></span>
					</el-col>
				</el-row>
			</div>
		</el-col>
	</el-row>
</template>
<script type="text/javascript">
import CommonTop from '@/components/CommonTop'
	export default{
		name:"CaseDetail",
		components:{CommonTop},
		data(){
			return{
				curPatient:{},
				doctorCaseObj:{
					complaint:"",
					disposal:"",
					diagnosis:"",
					symptom:""
				},
				recipeObj:{},
			}
		},
		mounted(){
			this.init(this.$route.params.recordUUID);
		},
		methods:{
			init:function(recordUUID){
				var vm = this;
				vm.$axios.getRecordByUUID(recordUUID).then(function(res){
		    			if (res.data&&res.data.data) {
		    				vm.curPatient= res.data.data;
		    				vm.handleStayTime();
		    				vm.$axios.queryDoctorCase(vm.curPatient.nodeUUID).then(function(res){
									if (res.data&&res.data.data) {
										vm.doctorCaseObj = res.data.data;
									}else{
										vm.generationDoctorCase();
									}
								});
		    				if (vm.curPatient.nodeUUID) {
								vm.$axios.queryRecipe(vm.curPatient.nodeUUID).then(function(res){
									if (res.data&&res.data.data&&res.data.data.length>0) {
										vm.recipeObj = JSON.parse(res.data.data[0].content);
									}
								});
							}
		    			}
		    		},function(res){
		    			console.log("error:"+res)
		    		});
			},
			generationDoctorCase:function(){
				var vm = this;
				//系统自动生成
				if (vm.curPatient.recordDiseaseTime) {
					vm.doctorCaseObj.complaint = vm.curPatient.complaintName + vm.curPatient.recordDiseaseTime;
				}else{
					vm.doctorCaseObj.complaint = vm.curPatient.complaintName;
				}

				if (vm.curPatient.sendDept=='住家观察') {
					vm.doctorCaseObj.disposal = (vm.curPatient.disposalAdvice+'不适随诊').replace(new RegExp('<br/>','gm'),'\r\n');
				}else{
					vm.doctorCaseObj.disposal = vm.curPatient.disposalAdvice?vm.curPatient.disposalAdvice.replace(new RegExp('<br/>','gm'),'\r\n'):"";
				}
				vm.doctorCaseObj.diagnosis =vm.curPatient.doctorDisease?vm.curPatient.doctorDisease.replace(new RegExp('###','gm'),'\r\n').replace('@@@','').replace(new RegExp(';','gm'),'\r\n'):"";
				vm.doctorCaseObj.symptom = vm.curPatient.recordSymptom?vm.curPatient.recordSymptom.replace(new RegExp("###","gm"),"\r\n").replace("@@@",""):"";
			},
			handleStayTime:function(){
				let vm =this;
				let stayTime = "";
				let times = "";
				if (vm.curPatient.departTime) {
					times = Math.ceil(((new Date(vm.curPatient.departTime)).getTime()-(new Date(vm.curPatient.startTime)).getTime())/60000);
				}else{
					times = Math.ceil(((new Date()).getTime()-(new Date(vm.curPatient.startTime)).getTime())/60000);
				}
				if (times/1440>=1) {
						stayTime = parseInt(times/1440) + "天";
					}
				if ((times%1440)/60>=1) {
					stayTime = stayTime + parseInt((times%1440)/60) + "小时";
				}
				if (times%60>1) {
					stayTime =stayTime + times%60 + "分钟";
				}
				vm.curPatient.stayTime= stayTime;
			}
		},
		watch: {
		  
		}
	}
</script>
<style type="text/css" scope>
#doctorCase{
	text-align: left;
	line-height: 35px;
	margin-bottom: 50px;
}
	#doctorCase label{
		font-weight: bolder;
	}
	.smtz{
		color: #000079;
		font-weight: bolder;
		font-size: 10pt;
	}
	.smtz span{
		font-weight: lighter;
		color: #000000;
		font-size: 10pt;
	}
	.line{
		width: 1px;
		height: auto;
		background-color: #000000;
		transform: rotate(15deg);
		/*transform-origin:-30px 0px;*/
		transform-origin:50% 50%;
	}
	.recipeContent{
		padding-left: 35px;
		line-height: 30px;
	}
	.caseDisposal{
		padding-left: 2.2em;
		line-height: 28px;
		margin-top: 0px;
	}
</style>